﻿using System;
using System.Web.UI;
using CurriculumData;

namespace CurriculumSite
{
    public partial class Subscriptions : Page
    {
        #region Members

        private readonly Controller _controller = new Controller();

        #endregion

        #region Event Handlers

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["CandidateId"] == null)
                Response.Redirect("~/Entry.aspx");
            DataBind();
        }

        protected void LinqDataSource_Selecting(object sender, System.Web.UI.WebControls.LinqDataSourceSelectEventArgs e)
        {
            var candidateId = (int) Session["CandidateId"];
            e.Result = _controller.GetSubscriptions(candidateId);
        }

        protected void unsubscribeASPxButton_Click(object sender, EventArgs e)
        {
            var vacanciesIds = subscribedASPxGridView.GetSelectedFieldValues("VacancyId");
            foreach (var vacancyId in vacanciesIds)
                _controller.Unsubscribe((int) vacancyId, (int)Session["CandidateId"]);
            Response.Redirect(Request.Path);
        }

        #endregion
    }
}
